package com.snowfield.lbsysconfig.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.snowfield.lbcommon.domain.Cluster;
import com.snowfield.lbcommon.service.IClusterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 负载集群Controller
 *
 * @author snowfield
 * @date 2024-03-20
 */
@RestController
@RequestMapping("/lbsysconfig/cluster")
public class ClusterController extends BaseController {
    @Autowired
    private IClusterService clusterService;

    /**
     * 查询负载集群列表
     */
    @PreAuthorize("@ss.hasPermi('lbsysconfig:cluster:list')")
    @GetMapping("/list")
    public TableDataInfo list(Cluster cluster) {
        startPage();
        List<Cluster> list = clusterService.selectClusterList(cluster);
        return getDataTable(list);
    }

    /**
     * 获取负载集群详细信息
     */
    @PreAuthorize("@ss.hasPermi('lbsysconfig:cluster:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        if (id == null || id != 1) {
            id = 1L;
        }
        return success(clusterService.selectClusterById(id));
    }

    /**
     * 修改负载集群
     */
    @PreAuthorize("@ss.hasPermi('lbsysconfig:cluster:edit')")
    @Log(title = "负载集群", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Cluster cluster) {
        return toAjax(clusterService.updateCluster(cluster));
    }

}
